home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 10-InfoSystems / mail / pop-account.frm.z / pop-account.frm
Encoding:
Text File  |  2002-06-12  |  9.2 KB  |  318 lines

  1. #!/usr/bin/perl5
  2. #
  3. # pop-account.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: pop-account.frm,v 1.21 1998/02/11 23:14:35 jrw Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $conf = "/etc/passwd";
  26. $dummy = "/etc/passwd.temp";
  27. $myname = "pop-account.cgi";
  28. $help_page = "pop-account-help.html";
  29. $title = "POP3 Mail Accounts";
  30. $popdir = "/usr/pop3";
  31.  
  32. $js_main =
  33. "which = \"none\";
  34. $js_help
  35. function runSubmit() {
  36.     // onClick gets processed before onSubmit
  37.     if(which == \"add\") return runAdd();
  38.     if(which == \"delete\") return runDelete();
  39.     return (true);
  40. }    
  41. function markAdd() { which = \"add\"; }
  42. function markDelete() { which = \"delete\"; }
  43. function markOther() { which = \"none\"; }
  44. function runAdd()  {
  45.     form = document.POPForm;
  46.     if (!testLogin(form)) return (false);
  47.     return (true);
  48. }
  49. function runDelete()  {
  50.     Ctrl = document.POPForm.chosen;
  51.     none = true;
  52.     for(i = 0; i < Ctrl.length; i++) { if (Ctrl.options[i].selected) { none = false; break; } }
  53.     if(none) { errorBox (Ctrl, \"No account selected.\"); return (false); }
  54.     return (true);
  55. }
  56. function testLogin(form) {
  57.     Ctrl = form.new_account;
  58.     if (Ctrl.value == \"\") { errorBox (Ctrl, \"To add a new account, first enter a login name for \\nthe account, then click the \\\"Add New Account\\\" button.\"); return (false); } 
  59.     error = testLoginChars(Ctrl.value); 
  60.     if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); }
  61.     if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); }
  62.     if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); }
  63.      return (true);
  64. }
  65. function testLoginChars(word) {
  66.     if (word.length > 8) return 1;
  67.     loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\";
  68.     for(j = 0; j < loginChars.length; j++) {
  69.         c = loginChars.charAt(j);
  70.         if (word.indexOf(c, 0) != -1) { illegal = c; return 2; }
  71.     }
  72.     for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; }
  73.     return 0;
  74. }
  75. function errorBox (Ctrl, ErrorMessage) {
  76.     alert (ErrorMessage);  Ctrl.focus();  return;
  77. }";
  78.  
  79.  
  80. $js_add =
  81. "which = \"none\";
  82. $js_help
  83. function runSubmit() {
  84.     // onClick must get processed before onSubmit
  85.     if(which == \"add\") return runAdd();
  86.     return (true);
  87. }    
  88. function markAdd() { which = \"add\"; }
  89. function markOther() { which = \"none\"; }
  90. function runAdd()  {
  91.     form = document.AddForm;
  92.     // JavaScript can't look at password fields.
  93.     return (true);
  94. }
  95. function errorBox (Ctrl, ErrorMessage) {
  96.     alert (ErrorMessage);  Ctrl.focus();  return;
  97. }";
  98.  
  99. print "Content-type: text/html\n\n";
  100.  
  101. &get_fields;
  102.  
  103. &getAccounts;
  104.  
  105. if (%fld) {
  106.     $fld{'chosen'} =~ /([\w.-]+)/;
  107.     $fld{'chosen'} = $1;
  108.  
  109.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  110.     $help =~ s/cgi$/hlp/;
  111.     exec $help if ($fld{'help'} eq "Help");
  112.  
  113.     if ($fld{'add'}) { 
  114.         &formValid_add;
  115.         @test = getpwnam($fld{'new_account'});
  116.         &error(2,"Account already exists.") if $test[0];
  117.  
  118.         $val{'login'} = $fld{'new_account'};
  119.         &addAccount; 
  120.     }
  121.     elsif ($fld{'delete'}) { 
  122.         &error(2,"No account selected.") if !$fld{'chosen'};
  123.         $message = qq|Click "Ok" to save changes.|;
  124.         &generic($fld{'chosen'}); 
  125.     }
  126.     elsif ($fld{'doit'}) { 
  127.         &tryToDelete; 
  128.         &getAccounts; 
  129.         if (!$message) { $message = "No changes made."; }
  130.         &generic; 
  131.     }
  132.     elsif ($fld{'doadd'}) { &formValid_doAdd; &doAdd; &getAccounts; &generic; }
  133.     else { $message = "Use buttons to submit form."; &generic; } 
  134.     
  135. } else { 
  136.     $NSstatus = &checkForNS;
  137.  
  138.     if ($NSstatus) { 
  139.         &title_block($title);
  140.         &header_block($title);
  141.         print "<i>NS Mail is currently running.  To enable POP3 Mail, first
  142.                disable NS Mail.</i>";
  143.     } else {
  144.         &generic;
  145.     }
  146. }
  147.  
  148. sub checkForNS {
  149.     local($mail_process) = "NscpMail";
  150.     local($ret) = 0;
  151.     open(PSNS, "/bin/ps -ef |");
  152.     while (<PSNS>) {
  153.     if ($_ =~ m:$mail_process:) { $ret = 1; }
  154.     }
  155.     close(PSNS);
  156.     $ret;
  157. }
  158.  
  159. sub formValid_add {
  160.     &error(1,qq|To add new account, first enter in login name for new account, 
  161.         then click "Add New Account" button.|) if !$fld{'new_account'};
  162.     &error(1,qq|Invalid login name.|) if $fld{'new_account'} =~ /$LOGINCHARS/o;
  163. }
  164.  
  165. sub formValid_doAdd {
  166.     if (!$fld{'password'}) 
  167.     { &error(0,"You must enter a password."); }
  168.     if ($fld{'password'} ne $fld{'passcheck'}) 
  169.     { &error(0,"Input passwords not equivalent."); }
  170.     &error(0,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o;
  171. }
  172.  
  173. sub error {
  174.     &error_block($_[1]);
  175.     %val = %fld;
  176.     if ($_[0] == 0) { &addAccount; }
  177.     if ($_[0] == 1 || $_[0] == 2) { undef @_; &generic; }
  178.     exit 0;
  179. }
  180.  
  181. sub tryToDelete {
  182.     $account = $fld{'del_name'};
  183.     if ($account eq "") { return; }
  184.  
  185.     open(IN,"< $conf");
  186.     open(OUT,"> $dummy");
  187.     while(<IN>) {
  188.     $line = $_;
  189.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  190.     @items = split(/:/,$line);
  191.     if ( ($items[5] =~ /^$popdir/) && $items[0] eq $account) {
  192.         next;
  193.     } else { print OUT $line; }
  194.     }
  195.     close(IN);
  196.     close(OUT);
  197.     rename($dummy, $conf);
  198.  
  199.     $message = "Account deleted.";    
  200. }
  201.  
  202. sub doAdd {
  203.     local($lgname) = $fld{'login'};
  204.     $userdir = $popdir."/$lgname";
  205.     &add_password($lgname,$fld{'password'},2000,20,$lgname." pop3",
  206.         $userdir, "/bin/false");
  207.  
  208.     if (! -d $popdir) {
  209.     mkdir($popdir, 0755);
  210.     }
  211.     mkdir($userdir, 0755);
  212.     chown((getpwnam($lgname))[2,3], $userdir);
  213.     $message = "New account added.";
  214. }
  215.  
  216. sub addAccount {
  217.     &js_title_block($title,$js_add);
  218.     &header_block("Add New POP3 Mail Account");
  219.  
  220.     print "<form action=$myname method=post name=AddForm onSubmit=\"return runSubmit()\">\n";
  221.  
  222.     print "<center><table>";
  223.  
  224.     print "<input type=hidden name=login value=$val{'login'}>";
  225.  
  226.     print "<tr><th align=left>Login name:</th><td><tt>",
  227.       $val{'login'},"</tt></td></tr>";
  228.  
  229.     print "<tr><th align=left>Password:</th><th align=left>";
  230.     print qq|<input type=password name="password" size=20>|;
  231.     print "</th></tr>";
  232.  
  233.     print "<tr><th align=left>(Password again):</th><th align=left>";
  234.     print qq|<input type=password name="passcheck" size=20>|;
  235.     print "</th></tr>";
  236.  
  237.     print "</table></center><br>";
  238.  
  239.     print &js_buttons('doadd','Ok','onClick="markAdd()"',
  240.         'onClick="markOther()"',
  241.         "onClick=\"do_help('$help_page'); return (false)\"");
  242.  
  243.     print "</form></body></html>";
  244. }
  245.  
  246. sub getAccounts {
  247.     $i = 0;
  248.     open(IN,"< $conf");
  249.     while(<IN>) {
  250.     $line = $_;
  251.     if ($line =~ /^\s*\#/) { next; }
  252.     @items = split(/:/,$line);
  253.     chop $items[5];
  254.     if ($items[5] =~ /^$popdir/) {
  255.         $name[$i] = $items[0];
  256.         $i++;
  257.     }
  258.     }
  259.     $number = $i;
  260.     close(IN);
  261. }
  262.  
  263. sub generic {
  264.         if (! -e "/usr/freeware/lib/popper") {  
  265.             print "<center><h2>POP3 Mail Accounts</h2></center>\n",
  266.             "<i>POP3 Mail Server software is not installed on this system. ",
  267.             "Please install the subsytem </i><b>fw_BSDqpopper</b><i> ", 
  268.             "from the WebFORCE CD or the <A ",
  269.             "HREF=\"http://www.sgi.com/TasteOfDT/public/freeware.html\" ",
  270.             "target=\"FREEWARE\">SGI freeware CD.</i>";
  271.             exit 0;
  272.         }
  273.  
  274.     &js_title_block($title,$js_main);
  275.     &header_block($title);
  276.  
  277.     %val = %fld;
  278.  
  279.     if (!$number && !$message) { $message = "No existing POP3 accounts."; }
  280.  
  281.     print "<i>$message</i>";
  282.  
  283.     print "<form action=$myname method=post name=POPForm onSubmit=\"return runSubmit()\">\n";
  284.     
  285.     if ($_[0]) { print qq|<input type=hidden name="del_name" value=$_[0]>|; }
  286.  
  287.     print "<center><table width=400>";
  288.  
  289.     print "<tr><td></td><th align=left>Login Name</th></tr>";
  290.  
  291.     print qq|<tr><td><input type=submit name="add" 
  292.     value="Add New Account" onClick="return markAdd()">
  293.     </td><td><input name="new_account" value="$val{'new_account'}" size=20></td></tr>|;
  294.     
  295.     if ($number) {
  296.         undef @locList;
  297.         for ($i=0;$i<$number;$i++) { 
  298.             if ($_[0] ne $name[$i]) { push(@locList,$name[$i]); }
  299.         }
  300.  
  301.         print qq|<tr><td valign=top><input type=submit name="delete" 
  302.         value="Delete Selected Account" onClick="return markDelete()"></td><td>|;    
  303.  
  304.         print &choice_list(*locList,"chosen",20);
  305.  
  306.         print "</td></tr>";
  307.     }
  308.  
  309.     print "</table></center><br>";
  310.  
  311.     print &js_buttons('doit','Ok','onClick="markOther()"',
  312.         'onClick="markOther()"',
  313.         "onClick=\"do_help('$help_page'); return (false)\"");
  314.  
  315.     print "</form></body></html>";
  316. }
  317.  
  318.